﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Xml;
using System.Xml.Schema;
using System.IO.IsolatedStorage;
using System.Xml.Linq;

namespace Gre_Wp7
{
    public class XmlFile
    {
        private const string filePath = "Test.xml";

        public static XmlReader ReadDataFromIsolatedStorageXmlDoc()
        {
            using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
            {

                using (var isoFileStream = new IsolatedStorageFileStream(filePath, System.IO.FileMode.OpenOrCreate, storage))
                {
                    using (XmlReader reader = XmlReader.Create(isoFileStream))
                    {
                        return reader;
                    }
                }
            }
        }

        public static XDocument GetXmlDoc()
        {
            using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
            {


                System.IO.Stream testpath = Application.GetResourceStream(new Uri(@"Word/Test.xml", UriKind.Relative)).Stream;


                using (XmlReader reader = XmlReader.Create(testpath))
                {
                    return XDocument.Load(reader);
                }
                
            }
        }

        public static void SaveXmlDoc(XDocument xdoc)
        {
            System.IO.Stream testpath = Application.GetResourceStream(new Uri(@"Word/Test.xml", UriKind.Relative)).Stream;
            xdoc.Save(testpath);
        }

        public static XmlWriter WriteDataFromIsolatedStorageXmlDoc()
        {
            using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
            {

                using (var isoFileStream = new IsolatedStorageFileStream(filePath, System.IO.FileMode.OpenOrCreate, storage))
                {
                    using (XmlWriter writer = XmlWriter.Create(isoFileStream))
                    {
                        return writer;
                    }
                }
            }
        }
    }
}
